package homework.valid;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Main {

    public static void inputServer(int port) throws IOException {
        ServerSocket socket = new ServerSocket(port);

        Socket client = socket.accept();

        InputStream in = client.getInputStream();
        OutputStream out = client.getOutputStream();

        ForcedInput fi = new ForcedInput(in, out);

        System.out.println("远程客户端有效输入: "+fi.inputPositiveInt("年龄: "));
        client.close();
        socket.close();
    }

    public static void main(String[] args) throws IOException {
        if(args.length == 2 && args[0].equals("server")) {
            int port = Integer.parseInt(args[1]);
            inputServer(port);
        } else {
            ForcedInput fi = new ForcedInput();
            System.out.println(fi.inputPositiveInt("年龄: "));
        }
    }
}
